package net.sx.minemodule.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.OrientationHelper;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kedll.library.util.MyUtils;

import net.sx.minemodule.R;

import java.util.List;

/**
 * Created by Administrator 可爱的路人 on 2019/7/6.
 * Email:513421345@qq.com
 * 退款详情，下面的按钮
 */
public class RefundActionsView extends LinearLayout {
    private List<RefundDetailAction> actions;

    public RefundActionsView(Context context) {
        super(context);
        init();
    }

    public RefundActionsView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RefundActionsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setOrientation(OrientationHelper.HORIZONTAL);
        setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
        setPadding(dp10, 0, dp10, 0);
    }

    private int dp10 = MyUtils.dp2px(10F);

    public void setActions(List<RefundDetailAction> actions) {
        this.actions = actions;
        removeAllViews();
        if (actions != null) {
            for (RefundDetailAction r : actions) {
                TextView textView = new TextView(getContext());
                textView.setText(r.getActionName());
                textView.setBackgroundResource(R.drawable.mine_bg_2_eeeeee);
                textView.setPadding(dp10, 0, dp10, 0);
                LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, MyUtils.dp2px(30F));
                layoutParams.setMarginEnd(dp10);
                textView.setLayoutParams(layoutParams);
                textView.setTextColor(ContextCompat.getColor(getContext(), R.color.color_text_1));
                textView.setGravity(Gravity.CENTER);
                textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.text_size_2));
                textView.setOnClickListener(r.onAction);
                addView(textView);
            }
        }
    }

    public static class RefundDetailAction {
        private String actionName;
        private View.OnClickListener onAction;

        public RefundDetailAction(String actionName, OnClickListener onAction) {
            this.actionName = actionName;
            this.onAction = onAction;
        }

        public String getActionName() {
            return actionName;
        }

        public void setActionName(String actionName) {
            this.actionName = actionName;
        }

        public OnClickListener getOnAction() {
            return onAction;
        }

        public void setOnAction(OnClickListener onAction) {
            this.onAction = onAction;
        }
    }
}
